import _fetch from './request'
import axios from 'axios'
let _cancel = ''
function articlesTechnic (parent) {
  return _fetch({
    url: '/articles/technic',
    params: parent
  })
}

// 热门职位数据
function chartDataHot () {
  return _fetch({
    url: '/chart-data/hot'
  })
}

// 面经分享
function articlesShare (params) {
  try {
    _cancel()
  } catch {}
  return _fetch({
    url: '/articles/share',
    params,
    // 取消接口请求
    cancelToken: new axios.CancelToken(cancel => {
      _cancel = cancel
    })
  })
}

// 面经热搜
function ArticlesShareTopSearch () {
  return _fetch({
    url: '/articles/shareTopSearch'
  })
}

// 面经详情
function ArticlesShareId (id) {
  return _fetch({
    url: '/articles/share/' + id
  })
}

// 面经评论
function ArticlesCommentsId (id) {
  return _fetch({
    url: '/articles/comments/' + id
  })
}

// 发送评论
function articlesComments (data) {
  return _fetch({
    url: '/articles/comments',
    method: 'post',
    needToken: true,
    data
  })
}

// 收藏面经
function articlesCollect (data) {
  return _fetch({
    url: '/articles/collect',
    method: 'post',
    needToken: true,
    data
  })
}

// 点赞文章接口
function articlesStar (data) {
  return _fetch({
    url: '/articles/star',
    method: 'post',
    needToken: true,
    data
  })
}

// 评论点赞
function articleCommentsStar (data) {
  return _fetch({
    url: '/article-comments/star',
    method: 'post',
    needToken: true,
    data
  })
}

export {
  articlesTechnic,
  chartDataHot,
  articlesShare,
  ArticlesShareTopSearch,
  ArticlesShareId,
  ArticlesCommentsId,
  articlesComments,
  articlesCollect,
  articlesStar,
  articleCommentsStar
}
